import { MongooseModule, Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';
import { ShareDocument } from '../document/share.document';

export type RolesDocument = Roles;

@Schema()
export class Roles extends ShareDocument {
  // 角色名称
  @Prop({
    unique: true,
    required: true,
  })
  roleName: string;

  // 角色简介
  @Prop()
  description: string;

  // 角色开关
  @Prop({
    default: true,
  })
  off: boolean;

  // 权限列表
  @Prop({
    type: [Types.ObjectId],
    default: [],
    ref: 'Menus'
  })
  limits: Types.ObjectId[];
}

export const RolesSchema = SchemaFactory.createForClass(Roles);

RolesSchema.set('toJSON', { getters: true });

export const RolesMongooseModule = MongooseModule.forFeature([
  {
    name: Roles.name,
    schema: RolesSchema
  },
]);
